#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
设备编码工具 - 启动脚本
"""

import os
import sys
import subprocess

def check_dependencies():
    """检查依赖是否安装"""
    try:
        import webview
        import psutil
        print("✓ 所有依赖已安装")
        return True
    except ImportError as e:
        print(f"✗ 缺少依赖: {e}")
        return False

def install_dependencies():
    """安装依赖"""
    try:
        print("正在安装依赖...")
        subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
        print("✓ 依赖安装完成")
        return True
    except subprocess.CalledProcessError as e:
        print(f"✗ 依赖安装失败: {e}")
        return False

def main():
    """主函数"""
    print("=== 设备编码工具 ===")
    print("功能说明:")
    print("  • 获取设备信息（磁盘序列号+系统+MAC地址）")
    print("  • 生成MD5设备标识")
    print("  • 跳转到 https://api.xqnmz.com/device?auth={设备ID}")
    print("  • 支持窗口最大化、最小化、调整大小")
    print()
    
    # 检查依赖
    if not check_dependencies():
        print("需要安装依赖包...")
        if not install_dependencies():
            print("\n依赖安装失败，请手动运行以下命令:")
            print("pip install -r requirements.txt")
            input("按回车键退出...")
            return
    
    # 启动GUI应用
    try:
        print("启动GUI应用...")
        from gui_app import DeviceTrackerGUI
        
        app = DeviceTrackerGUI()
        app.run()
        
    except Exception as e:
        print(f"✗ 应用启动失败: {e}")
        input("按回车键退出...")

if __name__ == "__main__":
    main()